#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;
const int N = 510, M = 5210;

int n, m1, m2;
bool st[N];
int q[N], cnt[N], dist[N];
int h[N], e[M], ne[M], w[M], idx;

void add(int a, int b, int c){
    e[idx] = b;
    ne[idx] = h[a];
    w[idx] = c;
    h[a] = idx ++;
}

bool spfa(){
    memset(dist, 0, sizeof dist);
    memset(st, 0, sizeof st);
    memset(cnt, 0, sizeof cnt);
    memset(q, 0, sizeof q);
    int hh = 0, tt = 0;

    for(int i = 1; i <= n; i ++){
        q[tt++] = i;
        st[i] = true;
    }

    while(hh != tt){
        int t = q[hh ++];
        if(hh == N) hh = 0;
        st[t] = false;

        for(int j = h[t]; j != -1; j = ne[j]){
            int u = e[j];
            if(dist[u] > dist[t] + w[j]){
                dist[u] = dist[t] + w[j];
                cnt[u] = cnt[t] + 1;
                if(!st[u]){
                    q[tt++] = u;
                    if(tt == N) tt = 0;
                    st[u] = true;
                }

                if(cnt[u] >= n ){
                    return true;
                }
            }
        }
        
    }

    return false;
}

void solve(){
    idx = 0;
    memset(h, -1, sizeof h);
    scanf("%d%d%d", &n, &m1, &m2);

    for(int i = 0; i < m1; i ++){
        int a, b, c;
        scanf("%d%d%d", &a, &b, &c);
        add(a, b, c);
        add(b, a, c);
    }

    for(int i = 0; i < m2; i ++){
        int a, b, c;
        scanf("%d%d%d", &a, &b, &c);
        add(a, b, -c);
    }

    if(spfa()){
        printf("YES\n");
    }else{
        printf("NO\n");
    }
}

int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);

    int T;
    scanf("%d", &T);

    for(int i = 0; i < T; i ++){
        solve();
    }

    return 0;
}